from django.shortcuts import render
from rest_framework.generics import ListAPIView
from goods.models import SKU
from goods.serializers import SKUSerializers, SKUSearchSerializers
from goods.utils import StandardResultsSetPagination
from rest_framework.filters import OrderingFilter
from drf_haystack.viewsets import HaystackViewSet
# Create your views here.


class SKUListView(ListAPIView):
    serializer_class = SKUSerializers
    pagination_class = StandardResultsSetPagination
    filter_backends = [OrderingFilter]
    ordering_fields = ('create_time', 'price', 'sales')

    def get_queryset(self):
        pk = self.kwargs['pk']
        return SKU.objects.filter(category_id=pk, is_launched=True)


class SKUSearchView(HaystackViewSet):
    # pagination_class = StandardResultsSetPagination

    index_models = [SKU]

    serializer_class = SKUSearchSerializers
